package org.example.javax.security.kerberos.demo1;

import java.util.HashMap;
import java.util.Map;

import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
import javax.security.auth.login.Configuration;

public class Krb5Configuration extends Configuration {

    private AppConfigurationEntry[] entry = new AppConfigurationEntry[1];

    Map<String, String> paramMap = new HashMap<>();

    private AppConfigurationEntry krb5LoginModule = new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule", LoginModuleControlFlag.REQUIRED, paramMap);

    @Override
    public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
        if (entry[0] == null) {
            paramMap.put("debug", "true");

            //1.enter the username and passsword
            paramMap.put("useTicketCache", "true");


//            paramMap.put("doNotPrompt", "false");
//            paramMap.put("storeKey", "true");
//            paramMap.put("principal", "test1");
//            paramMap.put("ticketCache", "/Users/juntaozhang/src/hello-java/JavaSE/src/main/java/org/example/javax/security/kerberos/demo1/keytab_cache");

            //2.use keytab file
//      paramMap.put("doNotPrompt", "true");
//      paramMap.put("useKeyTab", "true");
//      paramMap.put("principal", "test");
//      paramMap.put("keyTab", "/Users/juntaozhang/src/hello-java/JavaSE/src/main/java/org/example/javax/security/kerberos/demo1/test.keytab");
//      paramMap.put("storeKey", "true");

            entry[0] = krb5LoginModule;
        }
        return entry;
    }

}
